package sbt;

import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import sbt.Login;
import sbt.model.Film;
import sbt.model.User;
import sbt.pages.AddFilmPage;
import sbt.pages.Page;
public class AddFilm extends sbt.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();
  
@BeforeClass
  public void testLogin() {
  	User user = new User().setLogin("admin").setPassword("admin");
  	app.getUserHelper().loginAs(user);
}
  
 @Test
  public void AddFilmPass() throws Exception {
		String filmname = "New Film";
		String filmyear = "2013";
		Film film = new Film().setTitle(filmname).setYear(filmyear );
		app.getFilmHelper().create(film);
		assertTrue(app.getFilmHelper().getFilmPage().getFilmName().equals(filmname +" (" + filmyear + ")" ));
   }

@Test
  public void AddFilmFail() throws Exception {
	String filmname = "New Film";
	String filmyear = null;
	Film film = new Film().setTitle(filmname).setYear(filmyear );
	app.getFilmHelper().create(film);
//	AddFilmPage addFilmPage1 = app.getFilmHelper().getAddFilmPage();
//	boolean waitPageLoaded1 = addFilmPage1.waitPageLoaded();
	assertTrue(app.getFilmHelper().getAddFilmPage().waitPageLoaded());
	 	
  }

 @AfterMethod
 public void toHome() throws Exception {
	app.getNavigationHelper().openMainPage();
 }

@AfterClass
 public void testLogout(){
//	  if (app.getUserHelper().isLoggedIn())
	app.getUserHelper().logout();
 }
 
}
